package cn.edu.mju.property.service.impl;

import cn.edu.mju.property.dao.NoticeDao;
import cn.edu.mju.property.dao.impl.NoticeDaoImpl;
import cn.edu.mju.property.entity.Notice;
import cn.edu.mju.property.entity.PageBean;
import cn.edu.mju.property.service.NoticeService;

import java.util.List;

public class NoticeServiceImpl implements NoticeService {

    private NoticeDao dao = new NoticeDaoImpl();

    @Override
    public boolean addNotice(Notice notice) {
        return false;
    }

    @Override
    public boolean delNotice() {
        return false;
    }

    @Override
    public boolean updateNotice(Notice notice) {
        return false;
    }

    @Override
    public PageBean<Notice> findNoticeByPage(String _currentPage, String _rows) {
        int currentPage = Integer.parseInt(_currentPage) ;
        int rows = Integer.parseInt(_rows) ;

        PageBean<Notice> pb = new PageBean<Notice>();
        pb.setCurrentPage(currentPage);
        pb.setRows(rows);

        //总记录数
        int totalCount = dao.findTotalCount();
        pb.setTotalCount(totalCount);

        //开始值
        int start = (currentPage - 1) * rows;
        List<Notice> list = dao.findNoticeByPage(start,rows);
        pb.setList(list);

        int totalPage = totalCount % rows == 0 ? (totalCount/rows) : (totalCount/rows) + 1;
        pb.setTotalPage(totalPage);

        return pb;
    }


    @Override
    public int findTotalCount() {
        return 0;
    }
}
